<template>
	<view class="index">
		<tabbar></tabbar>
		<view class="bg">
			<view @click="backto()" class="backtab">
				<!-- <uni-icons type="back" size="30"></uni-icons> -->
				<img src="@/static/chevron-left (1).png" alt=""
					style="width: 20px;height: 20px;margin-top: 112rpx;margin-left: 20rpx;">
			</view>
		</view>
		<view class="user" v-if="isLogin">
			<!-- <image :src="userinfo.avatar" mode="" style="width: 50px;height: 50px;"></image> -->
			<image src="@/static/logo3.png" mode="" style="width: 50px;height: 70px;"></image>
			<view class="right">
				<!-- <text class="t1">{{ userinfo.nickname }}</text> -->
				<text class="t1">{{ userinfo.nickname }}</text>
				<text class="t2" v-if="userinfo.mobile!=''">{{ userinfo.mobile }}</text>

				<view v-if="userinfo.mobile==''" style="width: 500rpx;display: flex;">
					<view>
						<input type="text" placeholder="请输入你的手机号码" v-model="dianhua" style="width:  100%;" />
						<view style="height: 3rpx; background-color: black;width: 100%;"></view>
					</view>
					<view @click="dianji()" style="background-color: #3294FF;width:50rpx;color: white; display: flex;
					  justify-content: center;align-items: center; height: 50rpx; width:80rpx;margin-left: 20rpx;margin-left: 40rpx;">
						确定</view>
				</view>

				<!-- <text class="t2">积分：{{ userinfo.score }}</text> -->
				<!-- <text class="t2 bio">{{ userinfo.bio }}</text> -->
			</view>
			<view class="slider" v-if="userinfo.dirver == 1">
				<switch :checked="isWorking" color="#75BAFD" @change="switchChange()" @click="getonline()" />
				<view style="font-size: 14px;">{{isWorking?"上线中":'未上线'}}</view>
			</view>
		</view>
		<view class="user" v-if="!isLogin">
			<view class="to-login" @tap="navigateTo('/pages/login/login')">请登录</view>
		</view>
		<view class="m_list">
			<!-- <view class="item" @tap="navigateTo('/pages/mine/updataUser')">
        <image src="../../static/yh.png" mode=""></image>
        <text class="t3">个人资料</text>
        <text class="icon right">&#xe60f;</text>
      </view> -->
			<navigator url="/pages/mine/order">
				<!-- @tap="navigateTo('/pages/mine/order')" -->
				<view class="item">
					<image src="@/static/mine/journey.png" mode=""></image>
					<text class="t3">我的行程</text>
					<text class="icon right">&#xe60f;</text>
				</view>
			</navigator>
			<view class="item" v-if="userinfo.dirver == 0"
				@tap="navigateTo(userinfo.dirver == 0 ? '/pages/mine/applyDriving' : '/pages/AmyDriving/myDriving')">
				<image src="@/static/mine/apply for.png" mode=""></image>
				<text class="t3">延代驾司机申请</text>
				<text class="icon right">&#xe60f;</text>
			</view>
			<!-- <view class="item" v-if="userinfo.dirver == 1"
				@tap="handleJddt">
				<image src="@/static/mine/hall.png" mode=""></image>
				<text class="t3">接单大厅</text>
				<text class="icon right">&#xe60f;</text>
			</view> -->
			<view class="item" v-if="userinfo.dirver == 1" @tap="onHandleReceivingHall">
				<image src="@/static/mine/hall.png" mode=""></image>
				<text class="t3">接单大厅</text>
				<text class="icon right">&#xe60f;</text>
			</view>
			<navigator url="/pagesA/myDriving/order">
				<!-- @tap="navigateTo('/pagesA/myDriving/order')" -->
				<view class="item" v-if="userinfo.dirver == 1">
					<image src="@/static/mine/Dashboard.png" mode=""></image>
					<text class="t3">工作台</text>
					<text class="icon right">&#xe60f;</text>
				</view>
			</navigator>
			<navigator url="/pagesA/clock in/clock in">
				<!-- @tap="navigateTo('/pagesA/clock in/clock in')" -->
				<view class="item" v-if="userinfo.dirver == 1">
					<image src="@/static/mine/打卡.png" mode=""></image>
					<text class="t3">打卡</text>
					<text class="icon right">&#xe60f;</text>
				</view>
			</navigator>
			<view class="item" @click.stop="phone">
				<image src="@/static/mine/组 2@3x.png" mode=""></image>
				<text class="t3">联系客服</text>
				<text class="icon right">&#xe60f;</text>
			</view>
			<!-- 	<view class="item" @tap="navigateTo('/pages/mine/setting')">
				<image src="@/static/mine/组 37@3x.png" mode=""></image>
				<text class="t3">设置</text>
				<text class="icon right">&#xe60f;</text>
			</view> -->
			<button class="del" v-if="userinfo.mobile!=='undefined'" @tap="logout">退出登录</button>
		</view>

	</view>
</template>

<script>
	const app = getApp();
	import tabbar from './mytabbar.vue';
	import helper from '../../common/helper.js';
	import api from '../../common/api.js';
	export default {
		comments: {
			tabbar,
		},
		data() {
			return {
				userinfo: {
					group_id: 1,
					nickname: '',
					score: 0,
					dirver: 0,
					sign: false,
					String: "",
				},
				isLogin: false,
				dianhua: "",
				isWorking: false // 初始状态为开启
			};
		},
		onLoad() {
			// console.log(11111);
			uni.showLoading({
				title: '加载中'

			});
			this.getUserInfo()
			this.videoregdata = uni.getStorageInfo(this.userinfo)

		},
		onShow() {
			if (!helper.hasLogin()) {
				this.isLogin = false;
			} else {
				this.isLogin = true;
				// this.getUserInfo();
			}


		},
		methods: {
			phone() {
				uni.makePhoneCall({
					phoneNumber: "0433 2459400"
				})
			},
			// navigateTo(userinfo.dirver == 0 ? '/pages/mine/applyDriving' : '/pagesA/myDriving/myDriving')
			onHandleReceivingHall() {
				// debugger
				if (!this.isWorking) {
					uni.showToast({
						title: '请先上线！',
						icon: 'error',
					})
				} else {
					uni.navigateTo({
						// this.userinfo.dirver == 0 ? '/pages/mine/applyDriving' : '/pagesA/myDriving/myDriving'
						url: "/pagesA/myDriving/myDriving"
					})
				}
			},
			async dianji() {
				const reg = /^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$/
				if (!reg.test(this.dianhua)) {
					console.log(1231);
					uni.showToast({
						title: "请输入正确的手机号",
						icon: 'none',
						duration: 2000,
					})
					return false
				}


				/* console.log(this.userinfo); */
				let data = {
					phone: this.dianhua,
					id: this.userinfo.id
				}
				this.userinfo.mobile = this.dianhua;
				let res = await api.getdianhua(data)
				uni.setStorageSync("mobile", this.dianhua, )
				this.getUserInfo()
			},
			backto() {
				uni.navigateTo({
					url: "/pages/index/index"
				})
			},
			logout() {
				api.logout();
				helper.clearUsetToken();
				uni.reLaunch({
					url: "/pages/login/login",
				});
			},
			async getUserInfo() {
				let res = await api.getUserInfo();
				this.userinfo = res.data;
				if (this.userinfo.mobile == 1) {
					this.userinfo.mobile = ""
				}else{
					uni.setStorageSync("mobile", this.userinfo.mobile)
				}
				
				console.log(this.userinfo)
				if (res.data.online_status == 0) {
					this.isWorking = false
				} else {
					this.isWorking = true
				}
				uni.setStorageSync('videoregdata', this.userinfo);
				uni.hideLoading();

			},
			// async getList() {
			//   let res = await api.getOrderTakingList(this.map);
			//   this.order = res.data;
			//   uni.stopPullDownRefresh();
			// },
			navigateTo(url) {
				if (helper.hasLogin()) {
					uni.reLaunch({
						url: url
					})
				} else {
					url = '/pages/login/login'
				}
			},
			switchChange() {
				this.isWorking = !this.isWorking;
			},
			async getonline() {
				let data = {
					online_status: this.isWorking == false ? 0 : 1,
				}
				let res = await api.getonline(data);
				// console.log('getonline', res);
				// if(res.code==1){
				// 	uni.showToast({
				// 		title: '操作成功',
				// 		icon: 'success',
				// 		duration: 2000
				// 	})
				// }else{
				// 	uni.showToast({
				// 		title: '打卡失败',
				// 		icon: 'error',
				// 		duration: 2000
				// 	})
				// }
			}
		},
	};
</script>

<style lang="scss" scoped>
	.index {
		background: #EEEEEE;
		height: 100vh;
	}

	page {
		background: #EEEEEE;
	}

	.del {
		background: #ffffff;
		color: #FF7E7C;
		// margin-top: 30rem;
		position: absolute;
		bottom: 2rpx;
		left: 0;
		right: 0;
		height: 50pt;
		line-height: 35pt;
	}

	.bg {
		width: 100%;
		height: 294upx;
		// line-height: 294upx;
		background: #EEEEEE;
		// background-color: #EEEEEE;
	}

	.user {
		margin: 0 auto;
		width: 100%;
		height: 194rpx;
		display: flex;
		align-items: center;
		// border-radius: 20upx;
		// margin-left: 5%;
		margin-top: -110upx;
		background-color: #ffffff;
		box-shadow: 1px 1px 4px 0px #dfdfdf;
		height: 240upx;

		.to-login {
			text-align: center;
			color: #32c45e;
			width: 100%;
		}

		image {
			width: 140upx;
			height: 140upx;
			margin: 40upx;
			border-radius: 50%;
		}

		.right {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.t1 {
				font-size: 28upx;
				font-weight: 800;
				margin-bottom: 5upx;

				text-align: left;
			}

			.t2 {
				font-size: 24upx;
				font-weight: 800;
			}

			.bio {
				margin-top: 30upx;
				color: #555555;
			}
		}
	}

	.slider {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-left: 30%;
		// margin-right: 10rpx;
		// background-color: #555555;
	}

	.m_list {
		width: 100%;
		// height: 610rpx;
		margin-top: 16rpx;
		background: #FFFFFF;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		opacity: 1;


		.item {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 34upx 20upx;
			border: 1rpx solid #D8D8D8;

			image {
				width: 50upx;
				height: 50upx;
			}

			.icon {
				text-align: right;
				width: 10%;
				font-size: 28upx;
				color: #d7d7d7;
			}

			.t3 {
				width: 75%;
				margin-left: 5%;
				font-size: 28upx;
			}
		}
	}

	.comment {
		width: 100%;
		height: 100%;
		background-color: #ffffff;

		.user {
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 28upx;
			padding-top: 3rem;

			image {
				width: 80upx;
				height: 80upx;
				border-radius: 50%;
			}

			.name {
				width: 40%;
				margin-left: 20upx;

				.item2 {
					font-size: 20upx;
					padding-left: 20upx;
				}
			}

			.phone {
				width: 40%;
				text-align: right;
			}
		}

		.money {
			text-align: center;
			padding-top: 40upx;
			height: 120upx;
			font-size: 28upx;

			text {
				margin-bottom: 10upx;
				color: #101010;
				font-size: 30upx;
			}
		}

		.comment-btn {
			width: 100%;
			border-radius: 0px;
			background-color: #5498F5;
			height: 90upx;
			color: #ffffff;
			border-top: 1px solid #dddddd;
			position: absolute;
			bottom: 0;
		}

		.iptbox {
			width: 100%;
			height: 100upx;
			text-align: center;
			background-color: #ffffff;
			font-size: 30upx;
			color: #898989;
			padding: 24upx;
			box-sizing: border-box;
		}

		.comment-btn:after {
			border: none;
		}

		.done {
			height: 90upx;
			width: 100%;
			border-radius: 0px;
			background-color: #5498F5;
			color: #ffffff;
			border-top: 1px solid #dddddd;
			position: absolute;
			bottom: 0;
		}

		.done:after {
			border: none;
		}
	}
</style>